/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package server;

import frame.Fserver;
import java.net.InetAddress;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.Naming;

/**
 *
 * @author Qiao BingZhi
 */
public class Server {
    

    private String hostName = null;
    private String port = "1099";
    private String serverName = "Server";
    private boolean runStatus = false;

    private _ZoneExchange Server =null;

    public Server() {
        //Initiale the hostName with the hostname of this machine
        try {
            hostName = InetAddress.getLocalHost().getHostAddress();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Get the value of hostName
     *
     * @return the value of hostName
     */
    public String getHostName() {
        return hostName;
    }

    /**
     * Set the value of hostName
     *
     * @param hostName new value of hostName
     */
    public void setHostName(String hostName) {
        this.hostName = hostName;
    }

    /**
     * Get the value of port
     *
     * @return the value of port
     */
    public String getPort() {
        return port;
    }

    /**
     * Set the value of port
     *
     * @param port new value of port
     */
    public void setPort(String port) {
        this.port = port;
    }

    /**
     * Get the value of serverName
     *
     * @return the value of serverName
     */
    public String getServerName() {
        return serverName;
    }

    /**
     * Set the value of serverName
     *
     * @param serverName new value of serverName
     */
    public void setServerName(String serverName) {
        this.serverName = serverName;
    }

    /**
     * Get the value of runStatus
     *
     * @return the value of runStatus
     */
    public boolean isRunStatus() {
        return runStatus;
    }

    /**
     * Set the value of runStatus
     *
     * @param runStatus new value of runStatus
     */
    public void setRunStatus(boolean runStatus) {
        this.runStatus = runStatus;
    }

    public void run() {
      //  if (System.getSecurityManager() == null) {
      //      System.setSecurityManager(new RMISecurityManager());
      //  }

        try {

            //Definition of port
            LocateRegistry.createRegistry(Integer.parseInt(this.port));

            //create the objet distance
            this.Server = new ZoneExchange();

            //Registre objet distance
            Naming.rebind(this.serverName, Server);
            this.runStatus=true;
        } catch (Exception e) {
            e.printStackTrace();
            this.runStatus=false;
        }
    }
    public void run(Fserver f)
    {
           this.run();
           try{
           this.Server.setFrame(f);
           }
           catch(Exception e)
           {
            e.printStackTrace();
           }
           
    }
}
